<?php
namespace Admin\Service;
use Think\Model;

class AdminService extends Model{

	protected $autoCheckFields = false;
	
	private $adminModel = null;
	
	function __construct() {
		
		parent::__construct();
		
		$this->adminModel = D("Admin");
	}
	
	public function login($username, $password){
		$userInfo = null;
		if (!empty($username) && !empty($password)){
			$condition["name"] = $username;
			$condition["pwd"] = md5($password);
			$condition["enabled"] = 1;
			$userInfo = $this->adminModel->scope("detail")->where($condition)->find();
			if ($userInfo){
				$userInfo["lastlogin"] = date("Y-m-d H:y:s");
				$this->adminModel->save($userInfo);
			}
		}
		return $userInfo;
	}
}